package com.ticket.controller;

import com.ticket.service.impl.SearchServiceImpl;
import com.ticket.entity.Search;
import com.ticket.service.SearchService;
import com.ticket.util.Page;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author 全谢民
 * @version 8.0
 * @description: TODO   用户搜索控制器
 * @date 2023/10/13 20:54
 */
public class UserSearchController {

    /**
     * @author 全谢民
     * @description TODO    用户搜索
     * @date 2023/10/16 14:05
     * @param request
     * @param response
     * @return java.lang.Object
     */
    public Object searchAll(HttpServletRequest request , HttpServletResponse response){
        //session
        HttpSession session = request.getSession();
        //获取service层对象
        SearchService ss = new SearchServiceImpl();
        //获取page对象
        Page<Search> page =new Page<>(4,1);
        String pageIndex = request.getParameter("index");
        if(pageIndex!=null && pageIndex!=""){
            page.setCurrPageNo(Integer.parseInt(pageIndex));
        }
        //获取值--地址，名称，类型
        String activityAddress = request.getParameter("activityAddress");
        String activityName = request.getParameter("activityName");
        String activityType = request.getParameter("activityType");
        //        将获取到的存入session
        session.setAttribute("activityAddress",activityAddress);
        session.setAttribute("activityName",activityName);
        session.setAttribute("activityType",activityType);
        //将值传入对象
        Search search = new Search(activityName,activityType,activityAddress);
        //获取list集合与获取的数
        page = ss.selViewSearchList(search,page);
        List<Search> loveList = ss.selLoverList(search);
        if(page.getDataList()!=null){
            session.setAttribute("page",page);
            session.setAttribute("loveList",loveList);
        }
        return "redirect:/user_page/search.jsp";
    }
}
